from student_test.config import PROJECT_DIR
import sqlite3
URL = "D:\chicaixiang\auto-test\Interface test\student\student_env\studentManagementSystem\db.sqlite3"

def execute_db(sql):
    """
    连接接口项目sqlite数据库，并执行sql语句
    :param sql: sql语句
    :return:
    """
    # 打开数据库连接
    conn = sqlite3.connect("{0}\\studentManagementSystem\\db.sqlite3".format(PROJECT_DIR))
    # conn = sqlite3.connect(r"D:\chicaixiang\auto-test\Interface test\student\student_env\studentManagementSystem\db.sqlite3")
    # 新建游标
    cursor = conn.cursor()
    # 执行sql
    cursor.execute(sql)
    # 获取执行结果
    result = cursor.fetchall()
    # 关闭游标、提交连接、关闭连接
    cursor.close()
    conn.commit()
    conn.close()
    return result


def init_db():
    """
    初始化数据库，删除掉departments的所有数据
    :return:
    """
    execute_db("delete from departments;")

if __name__ == '__main__':
    init_db()